package vg.services.graph_view_manager.realization.graph_view.smart_graph_view.realization.actions;

import vg.interfaces.ll_services.data_base_service.data.graph.Edge;
import vg.interfaces.ll_services.data_base_service.data.graph.Vertex;
import vg.services.graph_view_manager.interfaces.graph_view.IGraphRenderer;

import java.awt.*;
import java.util.Collection;

/**
 * Color of elements.
 *
 * @author Timur Zolotuhin (e-mail: tzolotuhin@gmail.com)
 */
public class SetColorAction extends DefaultActionAdapter {
    // Main data
    private Color color;

    private Collection<Vertex> vertices;
    private Collection<Edge> edges;

    public SetColorAction(Color color, Collection<Vertex> vertices, Collection<Edge> edges) {
        super("color action");

        this.color = color;
        this.vertices = vertices;
        this.edges = edges;
    }

    @Override
    public void action(final IGraphRenderer graphRenderer) {
        if (vertices != null) {
            for (Vertex vertex: vertices) {
                graphRenderer.setColor4Vertex(String.valueOf(color.getRGB()), vertex);
            }
        }

        if (edges != null) {
            for (Edge edge : edges) {
                graphRenderer.setColor4Edge(String.valueOf(color.getRGB()), edge);
            }
        }

        graphRenderer.refreshView();
    }
}
